<template>
  <transition name="fade">
    <router-view></router-view>
  </transition>
</template>

<script>
  import api from './utils/api'
  import util from '@/utils/util'
  import {commonMixin} from '@/utils/mixin'
  export default {
    mixins: [commonMixin],
    computed: {
      menuList () {
        return this.$store.getters.menuList
      }
    },
    watch: {
      $route (to, from) {
        this.$store.dispatch('setCurRouteName', to.name)
        this.findPath(this.menuList, to.meta.id, (result) => {
          this.$store.dispatch('setPath', result)
        })
      }
    },
    mounted () {
      this.init()
    },
    methods: {
      init () {
        //this.getDefaultAddress()
      },
      findPath (menuList, id, callback) {
        if (!id) {
          callback([])
          return
        }
        for (let j = 0; j < menuList.length; j++) {
          let temppath = []
          try {
            function getNodePath (node) {
              temppath.push(node.text)
              // 找到符合条件的节点，通过throw终止掉递归
              if (node.id === id) {
                throw ('GOT IT')
              }
              if (node.childNodes && node.childNodes.length > 0) {
                for (let i=0; i<node.childNodes.length; i++) {
                  getNodePath(node.childNodes[i])
                }
                // 当前节点的子节点遍历完依旧没找到，则删除路径中的该节点
                temppath.pop()
              } else {
                // 找到叶子节点时，删除路径当中的该叶子节点
                temppath.pop()
              }
            }
            getNodePath(menuList[j])
          } catch (e) {
            callback(temppath)
          }
        }
      },
    }
  }
</script>

<style>
  .el-table {
    font-size: 12px;
  }
  .table-expand {
    font-size: 0;
  }

  .table-expand label {
    width: 90px;
    color: #99a9bf;
  }

  .table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 48%;
  }

  .el-cascader-panel{
    border: 1px solid #e4e7ed
  }
  .el-dialog__footer {
    text-align: center;
  }
  .el-card__body {
    box-sizing: border-box;
    padding: 15px;
    /*min-height: 759px!important;*/
  }
</style>

